from rest_framework import serializers
from django.core.cache import cache


class LoginSerializer(serializers.Serializer):
    def update(self, instance, validated_data):
        pass

    def create(self, validated_data):
        pass

    telephone = serializers.CharField(max_length=11, min_length=11)
    smscode = serializers.CharField(max_length=4, min_length=4)

    def validate(self, attrs):
        telephone = attrs.get('telephone')
        smscode = attrs.get('smscode')
        cached_code = cache.get(telephone)
        if smscode != cached_code:
            return False
        return attrs
